import React, {PureComponent} from 'react';
import {EmbedSelector, InputComp} from 'jh-lib';
import {UserOutlined, InfoCircleOutlined} from '@ant-design/icons';
import {Button, Col, Form, Row, Tooltip} from "antd";

const embedObj = {
    "status": 200,
    "data": {
        "enabled": false,
        "embed": true,
        "options": [{
            "defaulted": false,
            "id": 377,
            "version": 0,
            "corp": "GRP",
            "code": "author",
            "name": "作者",
            "order": 1.00000000
        }, {
            "defaulted": false,
            "id": 378,
            "version": 0,
            "corp": "GRP",
            "code": "reader",
            "name": "读者",
            "order": 1.00000000
        }],
        "id": 85,
        "version": 0,
        "corp": "GRP",
        "code": "EMBED_ENUM_DATASECURITYAUTHORITY",
        "name": "数据操作权限",
        "spellCode": "shujucaozuoquanxian-sjczqx"
    }
};

export default class Test extends PureComponent {
    formRef = React.createRef();

    fetchCombo(ajaxData) {
        console.log('Test fetchCombo', ajaxData);
        return Promise.resolve(embedObj);
    }

    render() {
        return (
            <div>
                {/*<h3>前缀后缀</h3>*/}
                <Form component={false} ref={this.formRef}
                      validateMessages={{
                          required: "'${name}' 是必选字段",
                      }}
                      onValuesChange={(changedValues, allValues) => {
                          console.log('changedValues, allValues', changedValues, allValues)
                      }}>
                    <div className={'demo-contain'}>
                        <Row gutter={[16, 16]}>
                            <Col span={12} style={{height: 100}}>
                                <EmbedSelector
                                    appins={this}
                                    selector={'EMBED_ENUM_DATASECURITYAUTHORITY'}
                                    compLabel={"权限"}
                                    fieldName={'authorField'}
                                    value={{
                                        author: true,
                                        reader: false
                                    }}
                                    style={{width: '400px'}}
                                />
                            </Col>
                        </Row>
                        <Row>
                            <Button onClick={() => {
                                this.formRef.current.validateFields().then(value => {

                                })
                                console.log('this.formRef.current.getFieldsValue()', this.formRef.current.getFieldsValue())
                            }}>提交</Button>
                        </Row>
                    </div>
                </Form>
            </div>
        )
    }
}